class HOOKS {
  /**
 * 递归合并对象
 */
  static assign(target = {}, ...sources: any) {
    let obj = target
    for (let item of sources) {
      obj = this.assignObj(obj, item || {})
    }
    return obj
  }
  /**
* 递归合并对象
*/
  static assignObj(target: any = {}, sources: any = {}) {
    let obj = target
    if (typeof target !== 'object' || typeof sources !== 'object' || sources == null) {
      return sources
    }
    if (Array.isArray(sources)) {
      return sources
    }
    for (let key in sources) {
      // 如果target也存在 那就再次合并
      if (target.hasOwnProperty(key)) {
        obj[key] = this.assignObj(target[key], sources[key])
      } else {
        // 不存在就直接添加
        obj[key] = sources[key]
      }
    }
    return obj
  }
  /**
 * 深拷贝
 * @param obj
 */
  static deepClone(obj: any) {
    let objClone: any = Array.isArray(obj) ? [] : {}
    if (obj && typeof obj === 'object') {
      for (let key in obj) {
        if (obj.hasOwnProperty(key)) {
          //   判断ojb子元素是否为对象，如果是，递归复制
          if (obj[key] && typeof obj[key] === 'object') {
            objClone[key] = this.deepClone(obj[key])
          } else {
            //   如果不是，简单复制
            objClone[key] = obj[key]
          }
        }
      }
    }
    return objClone
  }

}
export default HOOKS